|
|
|
|
|
|
|
Private Sub Form_Load()
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.Source = "Select * from Publishers"
rs.Open , "DSN=BIBLIO"
Set rs.ActiveConnection = Nothing
DisplayCurrentRecord
End Sub |
|
|
|
|
|
|
|
|
The only changes from Listing 28.2 were to add two lines of code. You set the CursorLocation property so that records are stored on the client, and you disconnect the recordset by destroying its ActiveConnection object. However, I would bet that some skeptics in the audience need even more evidence that the recordset is indeed disconnected from the database. To prove this theory, run the sample project with the modification to create a disconnected recordset. When the first record is displayed on the screen, open Windows Explorer and temporarily rename the file BIBLIO.MDB to another name. Return to Visual Basic, and you will find that the program still functions normally. However, you cannot start the program a second time unless the database file exists. |
|
|
|
|
|
|
|
|
Earlier, you learned how records are locked to prevent multiple users from ''fighting" over the same record. Record locking takes on a different meaning when you use disconnected recordsets. If you are not connected to a database, then you are, in a sense, "checking out" the records, like you would check out books from a library. If you edit or change the data in the recordset, the changes are not reflected until you "check in" the records, or in database terms, perform a batch update to the database. Therefore, the type of record locking you have to use is known as batch optimistic. |
|
|
|
|
|
|
|
|
Batch updates allow you to make multiple changes to a recordset and apply them to the underlying database at once with the UpdateBatch method. You can even make a change to a disconnected recordset, reestablish the connection, and update the database. |
|
|
|
|
|
|
|
|
First, to use UpdateBatch, you must change the Recordset object's LockType property to use the adLockBatchOptimisitc record-locking method: |
|
|
|
|
|
|
|
|
rs.LockType = adLockBatchOptimistic |
|
|
|
|
|
|
|
|
After you retrieve a disconnected recordset, as in the preceding section of code, change one or more of the records by setting a new field value: |
|
|
|
|
|
|
|
|
rs.Fields(0)= "Edited Field Value"
rs.MoveNext
rs.Fields(0)= "Another Edited Field Value" |
|
|
|
|
|
|
|
|
Next, reestablish the connection by setting the recordset's ActiveConnection property to a new Connection object, as shown here: |
|
|
|
|
|